const redis = require('../../../../redis/init.js')
const constant = require("../../../../constant/index.js");
const getUserLikedArticles = async (req, res) => {
  const { user_id} = req.body
  const userLikedArticlesSetKey = `${constant.USER_LIKED_ARTICLES(user_id)}`;
  try {
    const data = await redis.sMembers(userLikedArticlesSetKey);
    //将likedArticles中的值转化为number类型
    const likedArticles = data.map((articleId) => Number(articleId));
    res.send({
      code: 200,
      likedArticles,  // 返回用户点赞的所有文章 ID 数组
    });
  } catch (error) {
    console.error("Redis 操作失败:", error);
    res.status(500).send({
      code: 500,
      message: "服务器内部错误",
    });
  }
};

module.exports = getUserLikedArticles;
